package com.easy.goods.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.bean.Productedsize;
import com.easy.bean.Products;
import com.easy.common.CommonResult;
import com.easy.goods.service.ProductSizeService;
@RestController
public class Productsize {
    @Autowired
     ProductSizeService productSizeService;
//    @RequestMapping(method = RequestMethod.GET, value = "getcategory")
//    public CommonResult getSuperCategoryList() {
//        return CommonResult.success(productSizeService.getSuperCategoryList());
//
//    }
    //分页
//    @RequestMapping(method = RequestMethod.GET, value = "getcategorylist")
//    public CommonResult getCategoryList(Page page, Category category) {
//        return CommonResult.success(productSizeService.getCategoryList(page, category));
//
//    }
    @RequestMapping(method = RequestMethod.GET, value = "getsize")
    public CommonResult getproduct(Products products) {
        List<Productedsize> productsList=   productSizeService.list();
        return CommonResult.success(productsList);
    }

    @PostMapping("postsize")
    public CommonResult postproduct(@RequestBody Productedsize productedsize) {
        return CommonResult.success(productSizeService.save(productedsize));
    }
    @PutMapping("updatesize")
    public CommonResult updateproduct(@RequestBody Productedsize productedsize) {
        return CommonResult.success(productSizeService.updateById(productedsize));
    }

    @DeleteMapping("deletesize/{id}")
    public CommonResult deleteproduct(@PathVariable Integer id) {

        return CommonResult.success(productSizeService.deleteCategory(id));
//        return CommonResult.success(productService.deleteproduct(id));
    }
    //@GetMapping("getcoreproduct")
//    public CommonResult getcoreproduct(@RequestBody Page ,Products products) {
//        Page<Products>  productsPage=new Page<>(page.getPage(),page.getSize());
//        return CommonResult.success(productService.page(page));
//    }
    @GetMapping("sizepage")
    public CommonResult selectPage(Page page,Productedsize productedsize) {
        System.out.println(page.getSize() + "-----999" + productedsize.getSpecname()+"111------"+ page.getCurrent());

        List list = productSizeService.list(page, new QueryWrapper<Productedsize>().like("specname", productedsize.getSpecname()));
        long b=productSizeService.count();
        System.out.println("总条数"+b);
        System.out.println("--------");
        int a= list.size();
        HashMap map = new HashMap();
        map.put("count",b);
        map.put("list",list);
        return CommonResult.success(map);
    }
//    @PutMapping("sizeshangxiajia/{id}")
//    public void shangxiajia(@PathVariable Integer id) {
//        productSizeService.updatesizeshangxiajia(id);
//    }


}
